package com.solo.controller;

import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;


@WebServlet("/api/login")
public class LoginServlet extends HttpServlet {
    private Gson gson = new Gson();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");

        // 简单的用户验证（实际项目中应该连接数据库）
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        boolean isValid = "admin".equals(username) && "123456".equals(password);

        if (isValid) {
            request.getSession().setAttribute("user", username);
            response.getWriter().write("{\"success\": true}");
        } else {
            response.getWriter().write("{\"success\": false, \"message\": \"用户名或密码错误\"}");
        }
    }
}